<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Ajax传递数据</title>
    <base th:href="@{/}">
    <script src="static/script/axios.js"></script>
</head>
<body>
    <h1>使用Ajax发送数据</h1>
    <button onclick="sendJsonUser()">发送简单的Json</button>
    <button onclick="sendJson()">发送复杂的Json</button>

    <script>
        /**
         * data: 原始数据格式传递数据！就会按照json的格式向后台传递数据！ json必须使用请求体传递！
         *       method = post | put
         * params:迎合后台的一种传递数据格式，将对应{}json转成后台识别的  key =value & key = value的形式
         *       method = 可以等于任何请求方式
         *
         *
         *
         *
         *
         *       标准写法
         *            function sendJSONMap() {
         *            axios({
         *                url:"[[@{/user/info}]]",
         *                method:"post",
         *                data:{
         *                    account:"root",
         *                    password:"123456",
         *                    ids:[1,2,3,3,4,6],
         *                    address:{city:"葫芦岛"},
         *                    gfs:[{name:"小井",age:48},{name:"小丽亚",age:34}]
         *                }
         *            }).then(function (data) {
         *                 console.log(JSON.stringify(data))
         *            });
         *        }
         */

        async function sendJsonUser(){
         const {data} =  await axios("/json/user/login",{
               method: "post",
               baseURL: "[[@{/}]]",
               data:{
                   account:"root",
                   password:"123456",
                   sex:2,
                   address:{city:"葫芦岛",province:"辽宁"}
               },
               params:{}
           });
           console.log(data);
       }
       async function sendJson(){
           const {data} =  await axios("/json/user/regist",{
               method: "post",
               baseURL: "[[@{/}]]",
               data:{
                   account:"root",
                   password:"123456",
                   ids:[1,2,3,3,4,6],
                   address:{city:"葫芦岛"},
                   gfs:[{name:"小井",age:48},{name:"小丽亚",age:34}]
               },
               params:{}
           });
           console.log(data);
       }

    </script>
</body>
</html>